We present a static analysis for determining the execution costs of lazily evaluated functional languages, such as Haskell. Time- and space-behaviour of lazy functional languages can be hard to predict, creating a significant barrier to their broader acceptance. This paper applies a type-based analysis employing and to statically determine upper bounds on evaluation costs. While amortisation performs well with finite recursive data, we significantly improve the precision of our analysis for co-recursive programs (i.e. dealing with potentially infinite data structures) by tracking self-references. Combining these two approaches gives the first automatic static analysis for both recursive and co-recursive definitions. Furthermore, we generalize the analysis to determine cost bounds for an arbitrary measure assigned to syntactic constructs (e.g. evaluation steps, applications, allocations, etc.). Notably, automatic inference only relies on first-order unification and linear programming solving. Our publicly available implementation demonstrates the practicability of our technique on editable non-trivial examples.
展开▼